package com.example.cloudorder.web;

import com.example.cloudorder.bean.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class OrderDo {

    @RequestMapping("order")
    public String index(HttpServletRequest request){
        final int port = request.getServerPort();
        return "order : " + port;
    }

    @RequestMapping("hello")
    public String hello(String name){
        return "hello " + name;
    }

    @RequestMapping("add")
    public int add(int a, int b){
        return a + b;
    }

    @RequestMapping("my/{name}")
    public String myName(@PathVariable String name){
        return "my name is " + name;
    }

    @RequestMapping("showUserByParam")
    public User showUser(User user){
        user.setAge(user.getAge() + 10);
        return user;
    }

    @RequestMapping("showUserByBody")
    public User showUser1(@RequestBody User user){
        user.setAge(user.getAge() + 10);
        return user;
    }

}
